﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：徐毅
    //
    // 文件名：OrderunDistributeDetail.cs
    // 文件功能描述：入库汇总 
    // 创建标识：徐毅2009-05-20
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
    // 审核时间：
    // 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.IBLL;
using HZ.Common;
using System.Threading;
using HZ.DrugTrade.Model;
using System.Collections.Generic;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Enterprise.OrderManage
{
    public partial class StorageTotal :BasePage
    {
        public StorageTotal()
        {
            this.ModuleNo = Module.入库单管理.ToString();
        }

        private IList<HZ.DrugTrade.Model.View.Distribution> DistributionlList;
        private IList<HZ.DrugTrade.Model.View.PurchaseOrderDetail> PurchaseOrderDetaillList;
        //private IBLL_Purchase iPurchase = (IBLL_Purchase)RemotingHelper.GetObject(typeof(IBLL_Purchase));
        IBLL_Purchase iPurchase = Factory.BLL_Purchase();
        int rowIndex;
        private DateTime? dtWarehouseTimeFrom, dtWarehouseTimeTo;
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
      

        #region 采购单明细查询条件
        private string strProjectName, strPinyinCode, strCompanyName_sc, strHospitalName, strOutlookc, strMedicineModelName,
            strProductName, strDetailOrderName;

        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //绑定所有项目
                //IList<ProcurementProject> projectList = ipb.GetAllProcurementProject();
                //this.ddl_Projectname.DataSource = projectList;
                //ddl_Projectname.DataTextField = "ProjectName";
                //ddl_Projectname.DataValueField = "ProjectID";
                //ddl_Projectname.DataBind();
                //ListItem item = new ListItem();
                //item.Text = Constants.ALL_ITEM_TEXT;
                //item.Value = Constants.ALL_ITEM_VALUE;
                //ddl_Projectname.Items.Insert(0, item);
                QueryData();
            }
        }

        private void QueryData()
        {
            //strProjectName = this.ddl_Projectname.SelectedValue.ToString();//new HZ.Common.ConvertHelper(cbxProjectName.SelectedValue).String;
            strHospitalName = this.txb_HospitalTag.Text.ToString().Trim();
            strOutlookc = this.txb_OutlookcTag.Text.ToString().Trim();
            
            strProductName = this.txb_ProdctNameTag.Text.ToString().Trim();
            strDetailOrderName = this.txb_OrderName.Text.ToString().Trim();
            //strPinyinCode = this.txtPinyinCode.Text.ToString().Trim();
            strCompanyName_sc = this.txb_Company_SCTag.Text.ToString().Trim();
            User user = CurrentAccount.GetUser();
            HZ.DrugTrade.Model.Query.PurchaseOrderDetail PurchaseOrderDetail = new HZ.DrugTrade.Model.Query.PurchaseOrderDetail();
            //PurchaseOrderDetail.OrderName = strDetailOrderName;
            PurchaseOrderDetail.ProjectID = this.ddlProjectid.SelectedValue;
            PurchaseOrderDetail.GoodsName = strProductName;
            PurchaseOrderDetail.OrderName = strDetailOrderName;
            PurchaseOrderDetail.PinyinCode = this.txtpinyincode.Text.Trim().ToUpper();
            //PurchaseOrderDetail.PinyinCode = strPinyinCode;
            PurchaseOrderDetail.CompanyName_SC = strCompanyName_sc;
            PurchaseOrderDetail.Material = this.txtMaterial.Text.Trim();
            PurchaseOrderDetail.CompanyID_PS = user.Org.OrgID;
            PurchaseOrderDetail.HospitalName = strHospitalName;
            PurchaseOrderDetail.Outlookc = strOutlookc;

            PurchaseOrderDetail.SortFields = "PlanTime desc,OrderName asc,GoodsName asc,Outlookc asc ";
            int itotlRecord = 0;
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            PurchaseOrderDetaillList = iPurchase.GetPurchaseOrderDetailInflow_ByWhere(PurchaseOrderDetail, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out itotlRecord);
            AspNetPager1.RecordCount = itotlRecord;
            this.gvwProduceCatalog.AutoGenerateColumns = false;
            this.gvwProduceCatalog.DataSource = PurchaseOrderDetaillList;
            this.gvwProduceCatalog.DataBind();
     
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            QueryData();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            QueryData();
        }

        protected void gvwProduceCatalog_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            //strProjectName = this.ddl_Projectname.SelectedValue.ToString();//new HZ.Common.ConvertHelper(cbxProjectName.SelectedValue).String;
            strHospitalName = this.txb_HospitalTag.Text.ToString().Trim();
            strOutlookc = this.txb_OutlookcTag.Text.ToString().Trim();

            strProductName = this.txb_ProdctNameTag.Text.ToString().Trim();
            strDetailOrderName = this.txb_OrderName.Text.ToString().Trim();
            //strPinyinCode = this.txtPinyinCode.Text.ToString().Trim();
            strCompanyName_sc = this.txb_Company_SCTag.Text.ToString().Trim();
            User user = CurrentAccount.GetUser();
            HZ.DrugTrade.Model.Query.PurchaseOrderDetail PurchaseOrderDetail = new HZ.DrugTrade.Model.Query.PurchaseOrderDetail();
            //PurchaseOrderDetail.OrderName = strDetailOrderName;
            PurchaseOrderDetail.ProjectID = this.ddlProjectid.SelectedValue; ;
            PurchaseOrderDetail.GoodsName = strProductName;
            PurchaseOrderDetail.OrderName = strDetailOrderName;
            //PurchaseOrderDetail.PinyinCode = strPinyinCode;
            PurchaseOrderDetail.PinyinCode = this.txtpinyincode.Text.Trim().ToUpper();
            PurchaseOrderDetail.CompanyName_SC = strCompanyName_sc;
            PurchaseOrderDetail.Material = this.txtMaterial.Text.Trim();
            PurchaseOrderDetail.CompanyID_PS = user.Org.OrgID;
            PurchaseOrderDetail.HospitalName = strHospitalName;
            PurchaseOrderDetail.Outlookc = strOutlookc;

            PurchaseOrderDetail.SortFields = "PlanTime desc,OrderName asc,GoodsName asc,Outlookc asc ";
            int itotlRecord = 0;
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            PurchaseOrderDetaillList = iPurchase.GetPurchaseOrderDetailInflow_ByWhere(PurchaseOrderDetail, 1, 0, out itotlRecord);
            System.Data.DataTable tb = HZ.Data.ModelConvert.GetDataTableFromModel(PurchaseOrderDetaillList);
            HZ.Excel.ExcelHelper.ExportDataForWeb(tb, gvwProduceCatalog);
        }

        protected void gvwProduceCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (ddlProjectid.SelectedItem.Value == "0002")
                {
                    e.Row.Cells[7].Text = "自主报价";
                }
                else
                {
                    e.Row.Cells[7].Text = "采购限价";
                }
            }
        }
    }
}
